package mybatis_demo;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.jack.model.User;

public class MyBatisDemo {

	public static void demo1() {
		String resource = "configuration.xml";
		InputStream inputStream = null;
		SqlSessionFactory factory = null;
		SqlSession session = null;
		try {
			inputStream = Resources.getResourceAsStream(resource);
			factory = new SqlSessionFactoryBuilder().build(inputStream);
			session = factory.openSession();
			/*UserMapper userMapper = session.getMapper(UserMapper.class);
			User user = userMapper.selectByPrimaryKey(1);*/
			User user=session.selectOne("org.jack.dao.UserMapper.selectByPrimaryKey", 3);
			System.out.println("name:"+user.getName()+",password:"+user.getPassword());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (session!=null) {
			session.close();
		}
	}

	public static void main(String[] args) {
		demo1();
	}
}
